package org.vnl.platform.web.impl.myfaces.dojo.component.renderer;

import java.io.IOException;

import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;

import org.apache.commons.lang3.StringUtils;

public class DojoRendererBase extends Renderer {

    protected void writeDojoId(ResponseWriter rw, String dojoId, String id) throws IOException {
        if (StringUtils.isBlank(dojoId)) {
            rw.writeAttribute("data-dojo-id", id, null);
        } else {
            rw.writeAttribute("data-dojo-id", dojoId, null);
        }
    }
    
    protected void writeDojoType(ResponseWriter rw, String type) throws IOException {
        rw.writeAttribute("data-dojo-type", type, null);
    }
    
    protected void writeDojoProps(ResponseWriter rw, String dojoProps) throws IOException {
        if (!StringUtils.isBlank(dojoProps)) {
            rw.writeAttribute("data-dojo-props", dojoProps, null);
        }
    }
    
    protected void writeGeneralProperty(ResponseWriter rw, String name, Object value) throws IOException {
        if (value != null) {
            if (value instanceof String) {
                if (!StringUtils.isBlank(value.toString())) {
                    rw.writeAttribute(name, value, null);
                }
            } else {
                rw.writeAttribute(name, value, null);
            }
        }
    }
}
